package maestro;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.HashMap;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author sala_a
 */
public class HiloEnviandoBroadcast implements Runnable{
    private HashMap<String, Boolean> direcciones;
    Thread hilo;

    public HiloEnviandoBroadcast(HashMap<String, Boolean> direcciones_) {
        direcciones=direcciones_;
        
    }
    
    void inicializar(){
        for(String s:direcciones.keySet()){
               direcciones.put(s, false);
        }
    }
     
    public void run() {
     try{
            DatagramSocket socket =new DatagramSocket();
            socket.setBroadcast(true);
            byte[] mensajeEnviar = "Soy tu master!!".getBytes();
                        
            while(true){
            DatagramPacket paqueteEnviar= new DatagramPacket(mensajeEnviar, mensajeEnviar.length,InetAddress.getByName("255.255.255.255"),6972);
            socket.send(paqueteEnviar);
            Thread.sleep(5000);
            inicializar();
            }
            
        }catch (Exception e){
        
        }    
    }
    
}
